package com.mq.dpca.msg;

import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;

import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.msg.client.wmq.WMQConstants;

public abstract class ReceiverFactory implements MessageListener,ExceptionListener{
	MQQueueConnectionFactory mcf;
	QueueConnection qconn;
	MQConfig mc = null;
	QueueSession session = null;
	QueueReceiver receiver = null;
	Queue queue = null;
	/**
	 * ��ʼ������
	 * @throws JMSException
	 */
	public void openConnection(ReceiverFactory receive)  {
		try {
			mc = MQConfig.getInstance();
			mcf = new MQQueueConnectionFactory();
			mcf.setConnectionNameList(mc.getMQ_HOST_NAME());
			mcf.setChannel(mc.getMQ_CHANNEL());
			mcf.setTransportType(WMQConstants.WMQ_CM_CLIENT);
			mcf.setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT);
			mcf.setCCSID(Integer.parseInt(mc.getMQ_CCSID()));
			mcf.setQueueManager(mc.getMQ_MANAGER());
			qconn = mcf.createQueueConnection();
			session = qconn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
		    queue = session.createQueue(mc.getMQ_QUEUE_SUB());
            receiver = session.createReceiver(queue);
            receiver.setMessageListener(receive);
            qconn.start();
            while (true) {
            	
            }
		} catch (NumberFormatException e) {		
			e.printStackTrace();
		} catch (JMSException e) {
			e.printStackTrace();
		}finally {
		}		
	}
    
}
